package com.wedata.腾讯;


import cn.hutool.core.codec.Base64;
import cn.hutool.json.JSONObject;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.tms.v20201229.TmsClient;
import com.tencentcloudapi.tms.v20201229.models.*;

import java.nio.charset.StandardCharsets;

public class 文本安全 {

    public static void main(String[] args) throws TencentCloudSDKException {
        String textContent = "我是谁啊";
        //Credential cred = new Credential("AKIDfMr7Azc6RYSMAtVt1v4430oQn392f3DC", "uZ2iANLDzb2KTRAdv3wZmqkhaKtPm172");//旧账号
        Credential cred = new Credential("AKIDZ5RZT8bpQr7C6nHZciroV3RnJk4Ofsxu", "wMYVUO8e0FKDrHVWJtrgU9cv1wc5SecM");
        // 实例化一个http选项，可选的，没有特殊需求可以跳过
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("tms.tencentcloudapi.com");
        // 实例化一个client选项，可选的，没有特殊需求可以跳过
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        // 实例化要请求产品的client对象,clientProfile是可选的
        TmsClient client = new TmsClient(cred, "ap-guangzhou", clientProfile);
        // 实例化一个请求对象,每个接口都会对应一个request对象
        TextModerationRequest req = new TextModerationRequest();

        //req.setContent(Base64.decode("Content").toString());

        req.setContent(Base64.encode(textContent.getBytes(StandardCharsets.UTF_8)));

        // 返回的resp是一个TextModerationResponse的实例，与请求对象对应
        TextModerationResponse resp = client.TextModeration(req);
        System.out.println(new JSONObject(resp));
        //{"Keywords":[],"RequestId":"10b0db56-4c5c-4c6e-b7ee-e814d92ad2f3","SubLabel":"SexOrgan","Label":"Porn","DetailResults":[{"LibId":"","LibName":"","Keywords":[],"SubLabel":"PersonalAttack","Label":"Abuse","LibType":0,"Suggestion":"Review","Score":79},{"LibId":"","LibName":"","Keywords":["白粉"],"SubLabel":"Drug","Label":"Illegal","LibType":0,"Suggestion":"Review","Score":71},{"LibId":"","LibName":"","Keywords":[],"SubLabel":"","Label":"Spam","LibType":0,"Suggestion":"Pass","Score":0},{"LibId":"","LibName":"","Keywords":[],"SubLabel":"","Label":"Terror","LibType":0,"Suggestion":"Pass","Score":0},{"LibId":"","LibName":"","Keywords":[],"SubLabel":"SexOrgan","Label":"Porn","LibType":0,"Suggestion":"Block","Score":92},{"LibId":"","LibName":"","Keywords":[],"SubLabel":"","Label":"Polity","LibType":0,"Suggestion":"Pass","Score":0},{"LibId":"","LibName":"","Keywords":[],"SubLabel":"","Label":"Ad","LibType":0,"Suggestion":"Pass","Score":0}],"BizType":"0","Suggestion":"Block","Score":92,"DataId":"","Extra":"","ContextText":""}
    }
}
